//
//  SelfViewController.m
//  Yiqidianyin
//
//  Created by apple on 15/8/9.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "SelfViewController.h"
#import "SelfViewManager.h"
#import "AFNetworking.h"


@interface SelfViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIButton *selfHead;
@property (weak, nonatomic) IBOutlet UILabel *selfName;

@property (weak, nonatomic) IBOutlet UITableView *SelfTable;
@property(nonatomic,strong)SelfViewManager *selfM;
@property(nonatomic,strong)AFHTTPRequestOperationManager *afManager;

@end

@implementation SelfViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.selfM = [SelfViewManager share];
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;
    self.selfM = [[SelfViewManager alloc]init];
    
    self.SelfTable.delegate = self;
    self.SelfTable.dataSource = self;
    [self getSelfInformation];

    
    
}

-(void)getSelfInformation
{
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *usertoken = [user objectForKey:@"usertoken"];
    
    [self.selfM getSelfWithToken:usertoken BlockHoudle:^(NSDictionary *dic) {
        NSString *str = [NSString stringWithFormat:@"%@",dic[@"nickName"]];
        self.selfName.text = str;
        
//        NSString *pcStr = [http stringByAppendingString:dic[@"pictureUrl"]];
        NSString *pcstr = dic[@"pictureUrl"];
        
        NSURL *url = [NSURL URLWithString:pcstr];
        NSLog(@"%@",url);
        UIImage *imgFromUrl =[[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:url]];
        [self.selfHead setBackgroundImage:imgFromUrl forState:0];
        
        
        [self.selfHead.layer setMasksToBounds:YES];
        
        [self.selfHead.layer setCornerRadius:40.0];
     }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
        return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"selfCell1"forIndexPath:indexPath];
        
        return cell;
    }
    else if (indexPath.row == 2)
    {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"selfCell2" forIndexPath:indexPath];
        return cell;
    }
    else if (indexPath.row == 3)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"selfCell3" forIndexPath:indexPath];
        return cell;
    }
    else
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"selfCell4" forIndexPath:indexPath];
        return cell;
    }
    
}



@end
